package com.study.date;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 通过threadLocal解决多线程问题
 * */
public class ThreadLocatTest {

    private static final  ThreadLocal<SimpleDateFormat> threadLocal=new ThreadLocal(){
        @Override
        protected SimpleDateFormat initialValue() {
            return new SimpleDateFormat("yyyy-MM-dd");
        }
    };

    public static final Date getDate(String date) throws Exception{
        //每个线程都单独获取对象
        return threadLocal.get().parse(date);
    }
}
